package com.wbc.demo.SingleCaseDemo;

import java.lang.reflect.Constructor;

/**
 * @author wangbingchen
 * @DATE: 2022/9/14
 */

public class SingleCaseTest {

    public static void main(String[] args) throws Exception {

        SingleCaseDemo instance = SingleCaseDemo.getInstance();
        SingleCaseDemo instance1 = SingleCaseDemo.getInstance();
        System.out.println("是否为同一个对象:"+(instance == instance1));


        //反射破坏单例 也是不行的 具体看 SingleCaseDemo 内部私有化方式
        Class<?> aClass = Class.forName("com.wbc.demo.SingleCaseDemo.SingleCaseDemo");
        Constructor<?> declaredConstructor = aClass.getDeclaredConstructor();
        declaredConstructor.setAccessible(true);
        Object o = declaredConstructor.newInstance();
        SingleCaseDemo instance2 = (SingleCaseDemo) o;
        System.out.println(instance2 == instance);


    }
}
